package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.utils.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import org.springframework.beans.BeanUtils;
import com.seahorse.youliao.service.SysRoleDeptService;
import org.springframework.validation.annotation.Validated;
import com.seahorse.youliao.vo.response.SysRoleDeptResponseVO;
import com.seahorse.youliao.vo.request.SysRoleDeptQueryVO;
import com.seahorse.youliao.vo.response.SysRoleDeptPageInfoVO;
import com.seahorse.youliao.service.entity.SysRoleDeptDTO;

/**
* describe: 角色和部门关联表
* @author : songqiang
* @date: 2020-01-17 09:23:45.758
**/
@RestController
@Api("SysRoleDeptController")
@RequestMapping("sysRoleDept")
@Validated
public class SysRoleDeptController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(SysRoleDeptController.class);
    
	@Autowired
    private SysRoleDeptService sysRoleDeptService;
    /**
     * 分页查询
     * @param sysRoleDeptQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public SysRoleDeptPageInfoVO selectPageList(@RequestBody @Valid SysRoleDeptQueryVO sysRoleDeptQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", sysRoleDeptQueryVO.toString());
        LOGGER.info(info);
        SysRoleDeptDTO sysRoleDept = BeanUtil.convert(sysRoleDeptQueryVO, SysRoleDeptDTO.class);

        Page<SysRoleDeptResponseVO> page = PageHelper.startPage(sysRoleDeptQueryVO.getPageNum(), sysRoleDeptQueryVO.getPageSize());
        List<SysRoleDeptDTO> sysRoleDeptList = sysRoleDeptService.getList(sysRoleDept);
        SysRoleDeptPageInfoVO sysRoleDeptPageInfo = new SysRoleDeptPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), sysRoleDeptPageInfo);
        List<SysRoleDeptResponseVO> voList = BeanUtil.convert(sysRoleDeptList, SysRoleDeptResponseVO.class);
        sysRoleDeptPageInfo.setList(voList);

        return sysRoleDeptPageInfo;
    }


}
